<?php
/**
 * Nad�b (Mak�-Nad�b)
 *
 * @filesource 
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    Freeware
 * @package    Nadeb_Controller
 * @subpackage Nadeb.Controller.Front
 * @version    1.0
 */

class Nadeb_Controller_Front extends Zend_Controller_Action 
{
	public function init()
	{
//		$MountApp = new Nadeb_Loader_MountApp();
		$headers = Nadeb_Header::get_instance();
		$headers->aplyDefaultHeader( $this->_getAllParams() );
		
		$this->_helper->layout->setLayout($this->_getParam("module"));
		
		if( $this->_getParam('ajax') == true )
			$this->_helper->layout->disableLayout();
		
	}
	
	public function recaptchaAction()
	{
		$file       = new Nadeb_Form_Captcha_File();
		$this->name = $file->get( $this->_getParam('bg'), $this->_getParam('font') );
		
		$this->view->response = $this->name;
		
		$this->_helper->layout->disableLayout();
		$this->renderScript("ajax/response.phtml");
	}
	
	public function structureAction()
	{
		$html = "
		<div id='criarMVC'>
			<h1>Criar MVC</h1>
			<input class='input01' type='text' value='nome_do_controller' /> 
			<a class='criar' href='/index/create-mvc/name/nome_controller/'>criar</a> | 
			<a class='excluir' href='/index/delete-mvc/name/nome_controller/'>excluir</a>
		</div>
		
		<div id='criarAction'>
			<h1>Criar Action</h1>
			<input class='input02' type='text' value='nome_do_controller' /> 
			<input class='input03' type='text' value='nome_da_action' /> <a href='/index/create-action/name/nome_controller/act/nome_action'>criar</a>
		</div>
		<script src='/public/default/javascript/jquery.min.js' type='text/javascript'></script>
		
		<script type='text/javascript'>
		$(document).ready(function()
		{
			$('a.criar').click(function()
			{
				if( $('.input01').val() == 'nome_do_controller' )
				{
					alert('Digite um nome para o controller')
					return false;
				}
				else
				{
					url = $('a.criar').attr('href').replace('nome_controller',$('.input01').val());
				}
				window.location.href = url;
				return false;
		  	});
		  	
			$('a.excluir').click(function()
			{
				if( $('.input01').val() == 'nome_do_controller' )
				{
					alert('Digite um nome para o controller')
					return false;
				}
				else
				{
					url = $('a.excluir').attr('href').replace('nome_controller',$('.input01').val());
				}
				var answer = confirm('esta certo disso rapaz??')
				if (!answer) return false
				else
					window.location.href = url;
				
				return false;
		  	});
		  	
			$('//criarAction a').click(function()
			{
				if( $('.input02').val() == 'nome_do_controller' )
				{
					alert('Digite um nome para o controller')
					return false;
				}
				else if( $('.input03').val() == 'nome_da_action' )
				{
					alert('Digite um nome para a action')
					return false;
				}
				else
				{
					url = $('//criarAction a').attr('href').replace('nome_controller',$('.input02').val());
					url = url.replace('nome_action',$('.input03').val());
				}
				window.location.href = url;
				return false;
		  	});
		
		
		
			$('.input01').click(function()
			{
				if( $('.input01').val() == 'nome_do_controller' )
					$('.input01').val('')
		  	});
		  	
			$('.input02').click(function()
			{
				if( $('.input02').val() == 'nome_do_controller' )
					$('.input02').val('')
		  	});
		  	
			$('.input03').click(function()
			{
				if( $('.input03').val() == 'nome_da_action' )
					$('.input03').val('')
		  	});
		});
		</script>
		";
		
		/*
		http://sample/index/delete-mvc/name/teste
		
		
		*/
		$this->view->response = $html;
		$this->_helper->layout->disableLayout();
		$this->renderScript("ajax/response.phtml");
	}
	
	public function createMvcAction()
	{
		$mvc = new Nadeb_Model();
		$mvc->createMVC( $this->_getAllParams() );
		
		$this->view->response = $mvc->get_result();
		
		$this->_helper->layout->disableLayout();
		$this->renderScript("ajax/response.phtml");
		
	}
	
	public function createActionAction()
	{
		$mvc = new Nadeb_Model();
		$mvc->createAction( $this->_getAllParams() );
		
		$this->view->response = $mvc->get_result();
		
		$this->_helper->layout->disableLayout();
		$this->renderScript("ajax/response.phtml");
		
	}
	
	public function deleteMvcAction()
	{
		$mvc = new Nadeb_Model();
		$mvc->deleteMVC( $this->_getAllParams() );
		
		$this->view->response = $mvc->get_result();
		
		$this->_helper->layout->disableLayout();
		$this->renderScript("ajax/response.phtml");
		
	}
}